<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>JSP生成乘法表</title>
</head>
<body>
<form>
    <%
        String s = request.getParameter("num");
        if (s == null) {
            s = "";
        }
    %>
    <label for="number">请输入整数</label>
    <input type="number" min="1" id="number" name="num" value="<%=s%>">
    <input type="submit" value="确认">
</form>
<%--按上课讲的生成--%>
<table>
    <tbody>
    <%
        int num = Integer.parseInt("".equals(s) ? "0" : s);
        for (int i = 1; i <= num; i++) {
            out.println("<tr>");
            for (int j = 1; j <= num; j++) {
                if (j <= i) {
                    out.println("<td>" + i + "*" + j + "=" + i * j + "</td>");
                } else {
                    out.println("<td></td>");
                }
            }
            out.println("</tr>");
        }
    %>
    </tbody>
</table>
<hr/>
<%--我自己做的--%>
<table>
    <tbody>
    <%
        for (int i = 1; i <= num; i++) {
    %>
    <tr>
        <%
            for (int j = 1; j <= i; j++) {
        %>
        <td>
            <%=i%>*<%=j%>=<%=i * j%>
        </td>
        <%
            }
        %>
    </tr>
    <%
        }
    %>
    </tbody>
</table>
</body>
</html>
